<template>
  <div class="device-container">
    <!-- 页面标题区域 -->
    <div class="page-header">
      <div class="header-content">
        <h1 class="page-title">
          <i class="el-icon-monitor"></i>
          设备管理
        </h1>
        <p class="page-description">管理和监控所有智能床垫设备的状态和信息</p>
      </div>
      <div class="header-stats">
        <div class="stat-card online">
          <div class="stat-icon">
            <i class="el-icon-success"></i>
          </div>
          <div class="stat-info">
            <div class="stat-number">{{ onlineCount }}</div>
            <div class="stat-label">在线设备</div>
            <div class="stat-percentage">{{ getPercentage(onlineCount) }}%</div>
          </div>
        </div>
        <div class="stat-card offline">
          <div class="stat-icon">
            <i class="el-icon-warning"></i>
          </div>
          <div class="stat-info">
            <div class="stat-number">{{ offlineCount }}</div>
            <div class="stat-label">离线设备</div>
            <div class="stat-percentage">{{ getPercentage(offlineCount) }}%</div>
          </div>
        </div>
        <div class="stat-card total">
          <div class="stat-icon">
            <i class="el-icon-data-analysis"></i>
          </div>
          <div class="stat-info">
            <div class="stat-number">{{ total }}</div>
            <div class="stat-label">设备总数</div>
            <div class="stat-trend">
              <i class="el-icon-top"></i>
              <span>本月新增 {{ monthlyNew }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 搜索区域 -->
    <el-card class="search-card" shadow="hover">
      <div slot="header" class="card-header">
        <span class="card-title">
          <i class="el-icon-search"></i> 设备筛选
        </span>
        <div class="header-actions">
          <el-button type="text" @click="toggleAdvancedSearch">
            {{ showAdvancedSearch ? '收起高级筛选' : '展开高级筛选' }}
            <i :class="showAdvancedSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
          </el-button>
          <el-button type="text" @click="resetQuery">
            <i class="el-icon-refresh"></i> 重置
          </el-button>
        </div>
      </div>
      
      <el-collapse-transition>
        <div v-show="showSearch">
          <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px" class="search-form">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="设备序列号" prop="deviceSn">
                  <el-input
                    v-model="queryParams.deviceSn"
                    placeholder="请输入设备序列号"
                    clearable
                    prefix-icon="el-icon-key"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备型号" prop="model">
                  <el-input
                    v-model="queryParams.model"
                    placeholder="请输入设备型号"
                    clearable
                    prefix-icon="el-icon-cpu"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="MAC地址" prop="macAddress">
                  <el-input
                    v-model="queryParams.macAddress"
                    placeholder="请输入MAC地址"
                    clearable
                    prefix-icon="el-icon-connection"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备状态" prop="status">
                  <el-select v-model="queryParams.status" placeholder="请选择设备状态" clearable style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.online_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-collapse-transition>
              <div v-show="showAdvancedSearch">
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="固件版本" prop="firmwareVersion">
                      <el-input
                        v-model="queryParams.firmwareVersion"
                        placeholder="请输入固件版本"
                        clearable
                        prefix-icon="el-icon-download"
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="关联用户ID" prop="userId">
                      <el-input
                        v-model="queryParams.userId"
                        placeholder="请输入关联用户ID"
                        clearable
                        prefix-icon="el-icon-user"
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="最后在线时间" prop="lastSeenAt">
                      <el-date-picker clearable
                        v-model="queryParams.lastSeenAt"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择最后在线时间"
                        style="width: 100%">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="创建时间">
                      <el-date-picker
                        v-model="daterangeCreateTime"
                        style="width: 100%"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="更新时间">
                      <el-date-picker
                        v-model="daterangeUpdateTime"
                        style="width: 100%"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-collapse-transition>
            
            <el-row :gutter="20">
              <el-col :span="24" class="search-buttons">
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-collapse-transition>
    </el-card>

    <!-- 操作按钮区域 -->
    <el-card class="action-card" shadow="hover">
      <el-row :gutter="10" class="action-buttons">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="medium"
            @click="handleAdd"
            v-hasPermi="['system:device:add']"
            class="action-btn"
          >新增设备</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            icon="el-icon-edit"
            size="medium"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:device:edit']"
            class="action-btn"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="medium"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:device:remove']"
            class="action-btn"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            icon="el-icon-download"
            size="medium"
            @click="handleExport"
            v-hasPermi="['system:device:export']"
            class="action-btn"
          >导出</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="info"
            icon="el-icon-refresh"
            size="medium"
            @click="handleRefresh"
            class="action-btn"
          >刷新</el-button>
        </el-col>
      </el-row>
      
      <div class="view-switch">
        <el-radio-group v-model="viewMode" size="small">
          <el-radio-button label="table">
            <i class="el-icon-s-grid"></i> 表格视图
          </el-radio-button>
          <el-radio-button label="card">
            <i class="el-icon-s-order"></i> 卡片视图
          </el-radio-button>
        </el-radio-group>
      </div>
    </el-card>

    <!-- 表格视图 -->
    <transition name="fade" mode="out-in">
      <el-card v-if="viewMode === 'table'" key="table-view" class="table-card" shadow="hover">
        <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange" stripe>
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="设备ID" align="center" prop="id" width="80" />
          <el-table-column label="设备序列号" align="center" prop="deviceSn" :show-overflow-tooltip="true" />
          <el-table-column label="设备型号" align="center" prop="model" :show-overflow-tooltip="true" />
          <el-table-column label="MAC地址" align="center" prop="macAddress" :show-overflow-tooltip="true" />
          <el-table-column label="固件版本" align="center" prop="firmwareVersion" :show-overflow-tooltip="true" />
          <el-table-column label="关联用户ID" align="center" prop="userId" />
          <el-table-column label="设备状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.online_type" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <el-table-column label="最后在线时间" align="center" prop="lastSeenAt" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.lastSeenAt, '{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)"
                v-hasPermi="['system:device:query']"
              >详情</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:device:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:device:remove']"
                class="danger"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-card>
    </transition>

    <!-- 卡片视图 -->
    <transition name="fade" mode="out-in">
      <el-card v-if="viewMode === 'card'" key="card-view" class="card-view-container" shadow="hover">
        <el-row :gutter="20" class="device-cards">
          <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="device in deviceList" :key="device.id">
            <el-card class="device-card" shadow="hover" @click.native="handleView(device)">
              <div class="device-card-header">
                <div class="device-icon">
                  <i class="el-icon-monitor" :class="{
                    'online': device.status === '1', 
                    'offline': device.status === '0',
                    'fault': device.status === '2'
                  }"></i>
                </div>
                <div class="device-status">
                  <dict-tag :options="dict.type.online_type" :value="device.status"/>
                </div>
              </div>
              <div class="device-card-content">
                <h4 class="device-model">{{ device.model }}</h4>
                <p><i class="el-icon-key"></i> 序列号: {{ device.deviceSn }}</p>
                <p><i class="el-icon-connection"></i> MAC: {{ device.macAddress }}</p>
                <p><i class="el-icon-download"></i> 固件: {{ device.firmwareVersion }}</p>
                <p><i class="el-icon-user"></i> 用户ID: {{ device.userId }}</p>
                <p><i class="el-icon-time"></i> 最后在线: {{ parseTime(device.lastSeenAt, '{y}-{m}-{d} {h}:{i}') }}</p>
              </div>
              <div class="device-card-footer">
                <el-button size="mini" type="text" @click.stop="handleUpdate(device)" v-hasPermi="['system:device:edit']">
                  <i class="el-icon-edit"></i> 编辑
                </el-button>
                <el-button size="mini" type="text" class="danger" @click.stop="handleDelete(device)" v-hasPermi="['system:device:remove']">
                  <i class="el-icon-delete"></i> 删除
                </el-button>
              </div>
            </el-card>
          </el-col>
        </el-row>
        
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-card>
    </transition>

    <!-- 添加或修改智能床垫设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="设备序列号" prop="deviceSn">
              <el-input v-model="form.deviceSn" placeholder="请输入设备序列号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备型号" prop="model">
              <el-input v-model="form.model" placeholder="请输入设备型号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="MAC地址" prop="macAddress">
              <el-input v-model="form.macAddress" placeholder="请输入MAC地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="固件版本" prop="firmwareVersion">
              <el-input v-model="form.firmwareVersion" placeholder="请输入固件版本" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="关联用户ID" prop="userId">
              <el-input v-model="form.userId" placeholder="请输入关联用户ID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.online_type"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="最后在线时间" prop="lastSeenAt">
          <el-date-picker clearable
            v-model="form.lastSeenAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最后在线时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 设备详情对话框 -->
    <el-dialog title="设备详情" :visible.sync="viewOpen" width="900px" append-to-body>
      <div class="device-detail-container">
        <div class="device-detail-header">
          <div class="device-detail-icon">
            <i class="el-icon-monitor" :class="{
              'online': viewForm.status === '1', 
              'offline': viewForm.status === '0',
              'fault': viewForm.status === '2'
            }"></i>
          </div>
          <div class="device-detail-info">
            <h3>{{ viewForm.model }}</h3>
            <p>序列号: {{ viewForm.deviceSn }}</p>
            <div class="device-detail-status">
              <dict-tag :options="dict.type.online_type" :value="viewForm.status"/>
            </div>
          </div>
          <div class="device-detail-actions">
            <el-button type="primary" icon="el-icon-edit" @click="handleUpdate(viewForm)" v-hasPermi="['system:device:edit']">编辑</el-button>
          </div>
        </div>
        <el-divider></el-divider>
        
        <el-tabs v-model="activeTab" class="device-tabs">
          <el-tab-pane label="基本信息" name="basic">
            <el-descriptions :column="2" border>
              <el-descriptions-item label="设备ID">{{ viewForm.id }}</el-descriptions-item>
              <el-descriptions-item label="设备序列号">{{ viewForm.deviceSn }}</el-descriptions-item>
              <el-descriptions-item label="设备型号">{{ viewForm.model }}</el-descriptions-item>
              <el-descriptions-item label="MAC地址">{{ viewForm.macAddress }}</el-descriptions-item>
              <el-descriptions-item label="固件版本">{{ viewForm.firmwareVersion }}</el-descriptions-item>
              <el-descriptions-item label="关联用户ID">{{ viewForm.userId }}</el-descriptions-item>
              <el-descriptions-item label="设备状态">
                <dict-tag :options="dict.type.online_type" :value="viewForm.status"/>
              </el-descriptions-item>
              <el-descriptions-item label="最后在线时间">{{ parseTime(viewForm.lastSeenAt, '{y}-{m}-{d} {h}:{i}') }}</el-descriptions-item>
              <el-descriptions-item label="创建时间">{{ parseTime(viewForm.createTime, '{y}-{m}-{d} {h}:{i}') }}</el-descriptions-item>
              <el-descriptions-item label="更新时间">{{ parseTime(viewForm.updateTime, '{y}-{m}-{d} {h}:{i}') }}</el-descriptions-item>
            </el-descriptions>
          </el-tab-pane>
          
          <el-tab-pane label="运行状态" name="status">
            <div class="status-overview">
              <el-row :gutter="20">
                <el-col :span="8">
                  <div class="status-item">
                    <div class="status-icon online">
                      <i class="el-icon-success"></i>
                    </div>
                    <div class="status-info">
                      <div class="status-title">设备状态</div>
                      <div class="status-value">
                        <dict-tag :options="dict.type.online_type" :value="viewForm.status"/>
                      </div>
                    </div>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="status-item">
                    <div class="status-icon">
                      <i class="el-icon-time"></i>
                    </div>
                    <div class="status-info">
                      <div class="status-title">最后在线</div>
                      <div class="status-value">{{ parseTime(viewForm.lastSeenAt, '{y}-{m}-{d} {h}:{i}') }}</div>
                    </div>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="status-item">
                    <div class="status-icon">
                      <i class="el-icon-cpu"></i>
                    </div>
                    <div class="status-info">
                      <div class="status-title">固件版本</div>
                      <div class="status-value">{{ viewForm.firmwareVersion }}</div>
                    </div>
                  </div>
                </el-col>
              </el-row>
            </div>
          </el-tab-pane>
          
          <el-tab-pane label="操作记录" name="logs">
            <el-empty description="暂无操作记录" :image-size="100"></el-empty>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDevice, getDevice, delDevice, addDevice, updateDevice } from "@/api/system/device"

export default {
  name: "Device",
  dicts: ['online_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 显示高级搜索
      showAdvancedSearch: false,
      // 总条数
      total: 0,
      // 智能床垫设备表格数据
      deviceList: [],
      // 在线设备数量
      onlineCount: 2,
      // 离线设备数量
      offlineCount: 1,
      // 本月新增设备数
      monthlyNew: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情弹出层
      viewOpen: false,
      // 当前激活的标签页
      activeTab: 'basic',
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 更新时间时间范围
      daterangeUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceSn: null,
        model: null,
        macAddress: null,
        firmwareVersion: null,
        userId: null,
        status: null,
        lastSeenAt: null,
        createTime: null,
        updateTime: null
      },
      // 表单参数
      form: {},
      // 查看表单参数
      viewForm: {},
      // 视图模式：table-表格视图，card-卡片视图
      viewMode: 'card',
      // 表单校验
      rules: {
        deviceSn: [
          { required: true, message: "设备序列号不能为空", trigger: "blur" }
        ],
        model: [
          { required: true, message: "设备型号不能为空", trigger: "blur" }
        ],
        macAddress: [
          { required: true, message: "MAC地址不能为空", trigger: "blur" }
        ],
        firmwareVersion: [
          { required: true, message: "固件版本不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "关联用户ID不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "设备状态不能为空", trigger: "change" }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询智能床垫设备列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0]
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1]
      }
      if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
        this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0]
        this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1]
      }
      listDevice(this.queryParams).then(response => {
        this.deviceList = response.rows
        this.total = response.total
        this.calculateDeviceStats()
        this.loading = false
      })
    },
    // 计算设备统计数据
    calculateDeviceStats() {
      this.onlineCount = 0
      this.offlineCount = 0
      
      if (this.deviceList && this.deviceList.length > 0) {
        this.deviceList.forEach(device => {
          if (device.status == 1) {
            this.onlineCount++
          } else if (device.status === 0) {
            this.offlineCount++
          }
          // 状态为2（故障）的设备不计入在线或离线统计
        })
      }
    },
    // 获取百分比
    getPercentage(count) {
      if (this.total === 0) return 0
      return Math.round((count / this.total) * 100)
    },
    // 切换搜索区域
    toggleSearch() {
      this.showSearch = !this.showSearch
    },
    // 切换高级搜索
    toggleAdvancedSearch() {
      this.showAdvancedSearch = !this.showAdvancedSearch
    },
    // 刷新数据
    handleRefresh() {
      this.getList()
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deviceSn: null,
        model: null,
        macAddress: null,
        firmwareVersion: null,
        userId: null,
        status: null,
        lastSeenAt: null,
        createTime: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = []
      this.daterangeUpdateTime = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加智能床垫设备"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getDevice(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改智能床垫设备"
      })
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.viewForm = row
      this.viewOpen = true
      this.activeTab = 'basic'
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDevice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addDevice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除智能床垫设备编号为"' + ids + '"的数据项？').then(function() {
        return delDevice(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/device/export', {
        ...this.queryParams
      }, `device_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style lang="scss" scoped>
.device-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
}

// 页面标题区域
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  background: linear-gradient(135deg, #409EFF, #36A3F7);
  border-radius: 10px;
  padding: 25px;
  color: white;
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
  transition: all 0.3s ease;
  
  &:hover {
    box-shadow: 0 6px 16px rgba(64, 158, 255, 0.3);
    transform: translateY(-2px);
  }
  
  .header-content {
    .page-title {
      margin: 0 0 10px 0;
      font-size: 24px;
      font-weight: 600;
      
      i {
        margin-right: 10px;
        font-size: 28px;
      }
    }
    
    .page-description {
      margin: 0;
      font-size: 14px;
      opacity: 0.9;
    }
  }
  
  .header-stats {
    display: flex;
    gap: 20px;
    
    .stat-card {
      background: rgba(255, 255, 255, 0.15);
      backdrop-filter: blur(10px);
      border-radius: 10px;
      padding: 15px 20px;
      min-width: 140px;
      display: flex;
      align-items: center;
      transition: all 0.3s ease;
      
      &:hover {
        background: rgba(255, 255, 255, 0.25);
        transform: translateY(-3px);
      }
      
      .stat-icon {
        margin-right: 15px;
        
        i {
          font-size: 24px;
        }
      }
      
      .stat-info {
        .stat-number {
          font-size: 24px;
          font-weight: 700;
          line-height: 1;
        }
        
        .stat-label {
          font-size: 12px;
          opacity: 0.8;
          margin: 4px 0;
        }
        
        .stat-percentage {
          font-size: 12px;
          opacity: 0.8;
        }
        
        .stat-trend {
          font-size: 12px;
          opacity: 0.8;
          display: flex;
          align-items: center;
          
          i {
            margin-right: 4px;
          }
        }
      }
      
      &.online {
        .stat-icon i {
          color: #67C23A;
        }
      }
      
      &.offline {
        .stat-icon i {
          color: #E6A23C;
        }
      }
      
      &.total {
        .stat-icon i {
          color: #409EFF;
        }
      }
    }
  }
}

// 卡片通用样式
.el-card {
  border-radius: 10px;
  border: none;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  
  &:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    .card-title {
      font-weight: 600;
      color: #303133;
      
      i {
        margin-right: 8px;
      }
    }
    
    .header-actions {
      display: flex;
      gap: 10px;
    }
  }
}

// 搜索卡片
.search-card {
  margin-bottom: 20px;
  
  .search-form {
    .el-form-item {
      margin-bottom: 18px;
    }
  }
  
  .search-buttons {
    text-align: center;
    margin-top: 10px;
  }
}

// 操作按钮卡片
.action-card {
  margin-bottom: 20px;
  
  .action-buttons {
    display: flex;
    align-items: center;
    
    .action-btn {
      border-radius: 6px;
      font-weight: 500;
      transition: all 0.3s ease;
      
      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      }
    }
  }
  
  .view-switch {
    margin-top: 15px;
    text-align: right;
  }
}

// 表格卡片
.table-card {
  margin-bottom: 20px;
  
  .device-table {
    .action-link {
      margin-right: 8px;
      transition: all 0.3s ease;
      
      &:hover {
        transform: scale(1.1);
      }
      
      &.danger {
        color: #f56c6c;
      }
    }
  }
  
  .pagination {
    margin-top: 20px;
    text-align: right;
  }
}

// 卡片视图容器
.card-view-container {
  margin-bottom: 20px;
}

// 卡片视图样式
.device-cards {
  .device-card {
    margin-bottom: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 10px;
    overflow: hidden;
    
    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    }
    
    .device-card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      
      .device-icon {
        i {
          font-size: 24px;
          
          &.online {
            color: #67c23a;
          }
          
          &.offline {
            color: #e6a23c;
          }
          
          &.fault {
            color: #f56c6c;
          }
        }
      }
    }
    
    .device-card-content {
      h4.device-model {
        margin: 0 0 10px 0;
        font-size: 16px;
        color: #303133;
      }
      
      p {
        margin: 5px 0;
        font-size: 13px;
        color: #606266;
        
        i {
          margin-right: 5px;
          color: #909399;
        }
      }
    }
    
    .device-card-footer {
      margin-top: 15px;
      padding-top: 10px;
      border-top: 1px solid #ebeef5;
      display: flex;
      justify-content: space-between;
      
      .el-button {
        padding: 0;
        
        &.danger {
          color: #f56c6c;
        }
      }
    }
  }
}

// 设备详情对话框样式
.device-detail-container {
  .device-detail-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    
    .device-detail-icon {
      margin-right: 20px;
      
      i {
        font-size: 48px;
        
        &.online {
          color: #67c23a;
        }
        
        &.offline {
          color: #e6a23c;
        }
        
        &.fault {
          color: #f56c6c;
        }
      }
    }
    
    .device-detail-info {
      flex: 1;
      
      h3 {
        margin: 0 0 5px 0;
        font-size: 20px;
        color: #303133;
      }
      
      p {
        margin: 0 0 10px 0;
        color: #606266;
      }
    }
    
    .device-detail-actions {
      margin-left: 20px;
    }
  }
  
  .device-tabs {
    margin-top: 20px;
  }
  
  .status-overview {
    .status-item {
      display: flex;
      align-items: center;
      padding: 15px;
      background-color: #f9f9f9;
      border-radius: 8px;
      margin-bottom: 15px;
      
      .status-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 15px;
        background-color: #e6f7ff;
        
        &.online {
          background-color: #f0f9ff;
          
          i {
            color: #67c23a;
          }
        }
        
        i {
          font-size: 20px;
          color: #409eff;
        }
      }
      
      .status-info {
        .status-title {
          font-size: 14px;
          color: #909399;
          margin-bottom: 5px;
        }
        
        .status-value {
          font-size: 16px;
          font-weight: 600;
          color: #303133;
        }
      }
    }
  }
}

/* 过渡动画 */
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s ease;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}

// 响应式布局
@media (max-width: 1200px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    
    .header-stats {
      margin-top: 20px;
      width: 100%;
      justify-content: space-between;
    }
  }
}

@media (max-width: 768px) {
  .device-container {
    padding: 15px;
  }
  
  .page-header {
    .header-stats {
      flex-direction: column;
      gap: 10px;
      
      .stat-card {
        width: 100%;
      }
    }
  }
  
  .search-form {
    .el-col {
      margin-bottom: 10px;
    }
  }
  
  .action-buttons {
    flex-wrap: wrap;
  }
  
  .device-cards {
    .el-col {
      margin-bottom: 15px;
    }
  }
}
</style>